package com.dbuil.bleshoes.utils.glides;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.dbuil.bleshoes.R;


/**
 * Created buy 风凊扬 on 2019/9/3 0003
 */
public class GlideUtils {

    /**
     * 加载图片
     *
     * @param url
     * @param imageView
     */
    public static void loadImage(Context context, String url, ImageView imageView) {
        Glide.with(context)
                .load(url)
                .apply(new RequestOptions()
                        .centerCrop()
                        .dontAnimate()
                        .priority(Priority.NORMAL)
                        .placeholder(R.color.graf4)
                        //  .error(R.drawable.default_head)
                        .diskCacheStrategy(DiskCacheStrategy.RESOURCE)  //跳过磁盘缓存
                        .skipMemoryCache(false)//跳过内存缓存
                )
                .into(imageView);


    }


    /**
     * 加载圆角图片
     *
     * @param url
     * @param imageView
     */
    public static void loadRoundCornerImage(Context context, String url, ImageView imageView, int corner) {
//        Glide.with(context)
//                .load(url)
//                .apply(
//                        centerCropTransform()
//                                .priority(Priority.HIGH)
//                                .transform(new GlideRoundTransform(context, corner))  //圆形头像,自定义类
//                                .diskCacheStrategy(DiskCacheStrategy.NONE)  //跳过磁盘缓存
//                                .skipMemoryCache(true)     //跳过内存缓存
//                )
//                .into(imageView);

        Glide.with(context)
                .load(url)
                .apply(
                        new RequestOptions()
                                .centerCrop()
                                .dontAnimate()
                                .priority(Priority.NORMAL)
                                .transform(new GlideRoundTransform(context, corner))
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .skipMemoryCache(true)
                )
                .into(imageView);

    }


    /**
     * 加载头像
     *
     * @param avatar
     * @param imageView
     */
    public static void loadAvatar(Context context, String avatar, ImageView imageView) {

        Glide.with(context)
                .load(avatar)
                .apply(new RequestOptions()
                        .dontAnimate()
                        .centerCrop()
                       // .placeholder(R.drawable.default_head)
                        .error(R.drawable.default_head)
                        .transform(new GlideCircleTransform())
                        .diskCacheStrategy(DiskCacheStrategy.RESOURCE)  //跳过磁盘缓存
                        .skipMemoryCache(false)//跳过内存缓存
                )
                .into(imageView);

//        Glide.with(context)
//                .load(avatar)
//                .apply(centerCropTransform()
//                        .placeholder(R.drawable.default_head)
//                        .error(R.drawable.default_head)
//                        .priority(Priority.HIGH)
//                        .transform(new GlideCircleTransform())  //圆形头像,自定义类
//                        .diskCacheStrategy(DiskCacheStrategy.NONE)  //跳过磁盘缓存
//                        .skipMemoryCache(true))     //跳过内存缓存
//                .into(imageView);


//        Glide.with(context)
//                .load(avatar)
//                .apply(new RequestOptions()
//                                .fitCenter()
//                                .dontAnimate()
//                                .placeholder(R.drawable.default_head)
//                                .error(R.drawable.default_head)
//                                .transform(new GlideCircleTransform())
//                                .diskCacheStrategy(DiskCacheStrategy.RESOURCE)  //跳过磁盘缓存
//                        // .skipMemoryCache(true)//跳过内存缓存
//                )
//                .into(imageView);

    }

}
